package com.cpems.web.controller.system;

import java.util.List;
import java.util.Arrays;

import cn.dev33.satoken.annotation.SaIgnore;
import com.cpems.system.domain.vo.EquipmentInfoVo;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.cpems.common.annotation.RepeatSubmit;
import com.cpems.common.annotation.Log;
import com.cpems.common.core.controller.BaseController;
import com.cpems.common.core.domain.PageQuery;
import com.cpems.common.core.domain.R;
import com.cpems.common.core.validate.AddGroup;
import com.cpems.common.core.validate.EditGroup;
import com.cpems.common.enums.BusinessType;
import com.cpems.common.utils.poi.ExcelUtil;
import com.cpems.system.domain.vo.SysProjectInfoVo;
import com.cpems.system.domain.bo.SysProjectInfoBo;
import com.cpems.system.service.ISysProjectInfoService;
import com.cpems.common.core.page.TableDataInfo;

/**
 * 项目信息
 *
 * @author ruoyi
 * @date 2025-03-19
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/projectInfo")
public class SysProjectInfoController extends BaseController {

    private final ISysProjectInfoService iSysProjectInfoService;

    /**
     * 查询项目信息列表
     */
    @SaCheckPermission("system:projectInfo:list")
    @GetMapping("/list")
    public TableDataInfo<SysProjectInfoVo> list(SysProjectInfoBo bo, PageQuery pageQuery) {
        return iSysProjectInfoService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出项目信息列表
     */
    @SaCheckPermission("system:projectInfo:export")
    @Log(title = "项目信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(SysProjectInfoBo bo, HttpServletResponse response) {
        List<SysProjectInfoVo> list = iSysProjectInfoService.queryList(bo);
        ExcelUtil.exportExcel(list, "项目信息", SysProjectInfoVo.class, response);
    }

    /**
     * 获取项目信息详细信息
     *
     * @param projectId 主键
     */
    @SaCheckPermission("system:projectInfo:query")
    @GetMapping("/{projectId}")
    public R<SysProjectInfoVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long projectId) {
        return R.ok(iSysProjectInfoService.queryById(projectId));
    }

    /**
     * 新增项目信息
     */
    @SaCheckPermission("system:projectInfo:add")
    @Log(title = "项目信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody SysProjectInfoBo bo) {
        return toAjax(iSysProjectInfoService.insertByBo(bo));
    }

    /**
     * 修改项目信息
     */
    @SaCheckPermission("system:projectInfo:edit")
    @Log(title = "项目信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SysProjectInfoBo bo) {
        return toAjax(iSysProjectInfoService.updateByBo(bo));
    }

    /**
     * 删除项目信息
     *
     * @param projectIds 主键串
     */
    @SaCheckPermission("system:projectInfo:remove")
    @Log(title = "项目信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{projectIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] projectIds) {
        return toAjax(iSysProjectInfoService.deleteWithValidByIds(Arrays.asList(projectIds), true));
    }

    /**
     * 获取全部不同类型的项目数量及占比
     */
    @GetMapping("/getAllProjectType")
    @SaIgnore
    public R<List<SysProjectInfoVo>> getAllProjectType(@NotNull(message = "字典类型不能为空") String DictType) {
        return R.ok(iSysProjectInfoService.getAllProjectType(DictType));
    }

}
